*TITLE:HOW DO VOTERS HOLD POLITICIANS ACCOUNTABLE FOR PERSONAL WELFARE? EVIDENCE OF A SELF-SERVING BIAS
*JOURNAL: JOURNAL OF POLITICS
*AUTHOR: MARTIN VINÆS LARSEN
*FILE: STUDY 2 ANALYSES (FIGURE 3 & APPENDIX TABLES)
*DEPENDENCIES: eststo, blindschemes

*importing data
use "dkopt.dta", clear

*recodes
gen age=(2014-q1)
recode q2 (2=1) (1=0), gen (female)
recode q3 (1 2 3 4 5=0) (6 7 8 9=1), gen(educ)
gen gov=(5-q25)/4
replace gov=. if gov==-0.25
gen ego=(5-q56_q61_)
gen socio=(5-q56_q611)
recode ego  socio (-1=.)
gen privat=(5-q29_q29_)/4
gen national=(5-q29_q290)/4

*label
la var national "Government responsible for national economy"
la var privat "Government responsible for repondent's economy"
la var age "Age"
la var female "Woman (ref: man)"
la var educ "Some college"
la var soc "State of country's economy"
la var ego "State of personal economy"

*estimating models
tempfile q1 q2 q3 q4
eststo a: reg privat i.ego c.socio female age educ , r
margins, at(ego=(0 1 2 3 4)) saving(`q1', replace)
eststo b: reg national i.ego c.socio female age educ , r
margins, at(ego=(0 1 2 3 4)) saving(`q2', replace)
eststo c: reg privat ego socio female age educ, r
margins, at(ego=(0 1 2 3 4)) saving(`q3', replace)
eststo d: reg national ego socio  female age educ, r
margins, at(ego=(0 1 2 3 4)) saving(`q4', replace)

*regression table for appendix
esttab c d a b using "apdxfullopt.tex", replace drop(0.ego) star(+ 0.10 * 0.05) b(%9.2fc) label mtitles("Personal" "National" "Personal" "National") ///
stats(rmse r2 N, label(" $\sigma$" "R$^2$" "Observations") fmt(%9.2f %9.2f %9.0fc) )  ///
varlabel(_cons "Constant" 1.ego "Worse (ref: A Lot Worse)" 2.ego "The Same" 3.ego "Better" 4.ego "A Lot Better") ///
se  title(OLS regression of beliefs about government's capacity to affect national and personal economic condtions} \footnotesize \label{table:dkopt)

*descriptive statistics for appendix
keep if e(sample)==1
file open anyname using "desattrib.txt", write text replace 
file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{Descriptive statistics, DK-OPT survey\label{desattrib}} \footnotesize \begin{tabular}{l*{6}{c}}\hline\hline "
file write anyname _newline _col(0) "&Mean & SD & Min & Median & Max & n\\ \hline"
foreach x of var  national privat ego socio educ age female  {
su  `x' , d
file write anyname  _newline  _col(0) (`"`: var label `x''"') "&" _col(25) %9.2f  (r(mean)) " &" _col(45) %9.2f  (r(sd)) " &" _col(65) %9.2f  (r(min)) " &"   _col(85) %9.2f  (r(p50)) " &" _col(105) %9.2f  (r(max)) " &" _col(125) %9.0f  (r(N)) " \\"
}
file write anyname _newline _col(0) "\hline\hline"
file write anyname _newline _col(0) "\end{tabular}"
file write anyname _newline _col(0) "\end{table}"
file close anyname

*figure 3
use `q1', clear
gen soc=0
append using `q2'
replace soc=1 if soc==.
gen dummy=1
append using `q3'
replace soc=0 if soc==.
append using `q4'
replace soc=1 if soc==.
gen ci90_1=_margin+_se*1.64
gen ci90_2=_margin-_se*1.64
twoway line _margin _at1 if dummy!=1 & soc==1, lwidth(medthick) lcolor(black*0.1) lpattern(solid) || ///
line _margin _at1 if dummy!=1 & soc==0, lwidth(medthick) lcolor(black*0.5) lpattern(solid) || ///
rarea  _ci_l _ci_u _at1 if dummy==. & soc==1,  fcolor(black%20) lcolor(black%1)  || ///
rarea  _ci_l _ci_u _at1 if dummy==. & soc==0, fcolor(black%40) lcolor(black%1) || ///
rarea  ci90_1 ci90_2 _at1 if dummy==. & soc==1, fcolor(black%20) lcolor(black%1) || ///
rarea  ci90_1 ci90_2 _at1 if dummy==. & soc==0, fcolor(black%40) lcolor(black%1) || ///
scatter _margin _at1 if dummy==1 & soc==0, mfcolor(white%70) mlcolor(black%1) msym(O) msize(medlarge) || ///
scatter _margin _at1 if dummy==1 & soc==1, mfcolor(black%10) mlcolor(black%1) msym(O) msize(medlarge)  ///
scheme(plotplain) legend(order(2 1) ring(0) pos(1) ///
label(2 "your personal economic situation") label(1 "the national economic situation" "(placebo)")) ylabel(0.6(0.05)0.9) ///
xlabel(0 "A lot worse" 1 "Worse" 2 "The Same" 3 "Better" 4 "A Lot Better") xoverhangs ///
xtitle(" " "How is your own economic situation compared to 12 months ago?") ///
ytitle("To what extent can the government affect... ?") saving(a, replace)

graph export "newattrib.pdf", replace


********************************************************************************



